<template>
  <div class="business">
    <div class="business-info">
      <!--数据配置-->
      <vDeve></vDeve>
      <!--卡-->
      <vCard></vCard>
      <!--生活-->
      <vLife v-show="false"></vLife>
      <div class="bussiness-release">
        <Button type="primary" @click="releaseData">数据验证</Button>
        <Button type="primary" @click="releasePages" :disabled="disabled">生成文件</Button>
      </div>
    </div>
  </div>
</template>
<script type="text/ecmascript-6">
  import vDeve from './view/deve.vue'
  import vCard from './view/card.vue'
  import vLife from './view/life.vue'

  export default {
    data () {
      return {
        loginId: JSON.parse(sessionStorage.getItem('loginId')),
        dataId: JSON.parse(sessionStorage.getItem('dataId')),
        appId: JSON.parse(sessionStorage.getItem('appId')),
        disabled: true
      }
    },
    components: {
      vDeve,
      vCard,
      vLife
    },
    created () {
      this.getDataId()
    },
    methods: {
      getDataId () {
        let dataId = JSON.parse(sessionStorage.getItem('dataId'))
        if (!dataId && dataId !== 0) {
          this.$Modal.confirm({
            title: '提示',
            content: '请先配置前置条件信息',
            onOk: () => {
              this.$router.push('/initialization')
            },
            onCancel: () => {
              this.$Message.info('点击了取消')
            }
          })
        }
      },
      releaseData () {
        let url = this.api.bussiness.releaseData
        let params = {
          appId: this.appId,
          sign: 'RSA'
        }
        this.$axios.get(url, {params: params}).then((res) => {
          if (res.data.msg.code === '20000') {
            this.$Message.info({content: res.data.msg.message, duration: 5})
            this.disabled = false
          } else {
            this.$Message.error({content: res.data.msg.message, duration: 5})
          }
        }).catch((err) => {
          if (err) throw err
          this.$Message.error({content: '网络异常', duration: 5})
        })
      },
      releasePages () {
        let url = this.api.bussiness.releasePages
        let params = {
          appId: this.appId
        }
        this.$axios.get(url, {params: params}).then((res) => {
          if (res.data.msg.code === '20000') {
            this.$Message.info({content: res.data.msg.message, duration: 5})
          } else {
            this.$Message.error({content: res.data.msg.message, duration: 5})
          }
        }).catch((err) => {
          if (err) throw err
          this.$Message.error({content: '网络异常', duration: 5})
        })
      }
    }
  }
</script>
